package frontend.parser.node.expnode.binaryexpnodes;

import frontend.lexer.token.TokenType;
import frontend.parser.node.Node;
import utils.Pair;

import java.util.ArrayList;

public abstract class BinaryExpNode<C extends Node> extends Node {
    public static final TokenType[] MUL_EXP_ALLOWED_OPERATORS = new TokenType[] {
            TokenType.MULT, TokenType.DIV, TokenType.MOD
    };
    public static final TokenType[] ADD_EXP_ALLOWED_OPERATORS = new TokenType[] {
            TokenType.PLUS, TokenType.MINU
    };
    public static final TokenType[] REL_EXP_ALLOWED_OPERATORS = new TokenType[] {
            TokenType.LSS, TokenType.GRE, TokenType.LEQ, TokenType.GEQ
    };
    public static final TokenType[] EQ_EXP_ALLOWED_OPERATORS = new TokenType[] {
            TokenType.EQL, TokenType.NEQ
    };
    public static final TokenType[] LAND_EXP_ALLOWED_OPERATORS = new TokenType[] {
            TokenType.AND
    };
    public static final TokenType[] LOR_EXP_ALLOWED_OPERATORS = new TokenType[] {
            TokenType.OR
    };
    public BinaryExpNode() {
        super();
    }
    protected C headChildExp;
    protected final ArrayList<Pair<TokenType, C>> operations = new ArrayList<>();

    public void addHeadChildExp(C childExp) {
        super.add(childExp);
        this.headChildExp = childExp;
    }
    public void addOperation(TokenType tokenType, C childExp) {
        super.add(childExp);
        this.operations.add(new Pair<>(tokenType, childExp));
    }
    public abstract TokenType[] getAllowedOperators();
    public C getHeadChildExp() {
        return headChildExp;
    }
    public ArrayList<Pair<TokenType, C>> getOperations() {
        return operations;
    }
    public boolean hasOperation() {
        return !operations.isEmpty();
    }
}
